﻿@model PagedList.IPagedList<AppStore.Domain.Entities.Application>

@{
    ViewBag.Title = "Browse";
}

<p>
<div style="overflow: hidden;">
<h2>Browse</h2>
@{
    int iteration = 0;
    
    foreach (var item in Model)
    {
        if( (iteration % 3) == 0)
        {
            <div class="product_box no_margin_right">
                <img src="@Url.Action("GetImage","Application", new {item.applicationId})" alt="Image 01" />
                <h3>@Html.DisplayFor(modelItem => item.name)</h3>
                <p class="product_price">$@Html.DisplayFor(modelItem => item.price)</p>
                @Html.ActionLink("Szczegóły", "Details", new { applicationId = item.applicationId }, new { @class = "detail" })
            </div>
        }
        else
        {
            <div class="product_box">
                <img src="@Url.Action("GetImage","Application", new {item.applicationId})" alt="Image 01" />
                <h3>@Html.DisplayFor(modelItem => item.name)</h3>
                <p class="product_price">$@Html.DisplayFor(modelItem => item.price)</p>
                @Html.ActionLink("Szczegóły", "Details", new { applicationId = item.applicationId }, new { @class = "detail" })
            </div>
        }
        
    iteration++;
    }
}
</div>
<div style="overflow: hidden; text-align: center;">
    
    @if (Model.HasPreviousPage)
    {
        <a href="@Url.RouteUrl("BrowesePage", new {category = Model[0].Category.name, page = 1})"> << </a>
        @Html.Raw(" ")
        <a href="@Url.RouteUrl("BrowesePage", new {category = Model[0].Category.name, page = Model.PageNumber - 1})">Poprzednia</a>
     }
    else
    {
         @Html.Raw("<<")
         @Html.Raw(" ")
         @Html.Raw("Poprzednia")
    } 
    @if (Model.HasNextPage)
    {
        <a href="@Url.RouteUrl("BrowesePage", new {category = Model[0].Category.name, page = (Model.PageNumber+1)})">Następna</a>
        @Html.Raw(" ")
        <a href="@Url.RouteUrl("BrowesePage", new {category = Model[0].Category.name, page = Model.PageCount})">>></a>
    }
    else
    {
         @Html.Raw("Następna")
         @Html.Raw(" ")
         @Html.Raw(">>")
    }
    
<p style="text-align: center; margin-top: 5px;">Strona: @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber)
    z @Model.PageCount</p>
</div>